package com.crane.oss.web.controller.sports;


import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.crane.common.core.dto.MultiResponse;
import com.crane.common.core.dto.Response;
import com.crane.common.core.dto.SingleResponse;
import com.crane.common.core.exception.SysException;
import com.crane.common.core.utils.CollectionUtil;
import com.crane.oss.enums.SectionEnum;
import com.crane.oss.sports.XunFeiCommonApiService;
import com.crane.oss.sports.XunFeiTeachTestApiService;
import com.crane.oss.sports.bean.resquest.*;
import com.crane.oss.web.BaseBusinessController;
import com.crane.oss.xunfei.req.*;
import com.crane.oss.xunfei.resp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.util.*;

/**
 * @author bealon
 */
@Api(value = "NationTestController", tags = {"智慧体育-体测"})
@RestController
@RequestMapping("/sports/test")
public class NationTestController extends BaseBusinessController {

    @Resource
    XunFeiTeachTestApiService xunFeiTeachTestApiService;

    @Resource
    XunFeiCommonApiService xunFeiCommonApiService;


    @ApiOperation(value = "体侧项目类型", notes = "体侧项目类型")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestItemReq")
    @PostMapping("/getPhysicalTestItem")
    public MultiResponse<PhysicalTestItemResp> getPhysicalTestItem(@RequestBody QueryCourseTestItemReq request) {
        QueryPhysicalTestItemReq queryPhysicalTestItemReq = new QueryPhysicalTestItemReq();
        queryPhysicalTestItemReq.setType(request.getType());
        ApiListResponse<PhysicalTestItemResp> response = xunFeiCommonApiService.getPhysicalTestItem(queryPhysicalTestItemReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.ofWithoutTotal(response.getData());
        }
        return MultiResponse.ofWithoutTotal(new ArrayList<>());
    }

    @ApiOperation(value = "项目信息", notes = "项目信息")
    @PostMapping("/getTestCountryItem")
    public MultiResponse<TestCountryItemListResp> getTestCountryItem() {
        XunFeiApiRequest request = new XunFeiApiRequest();
        ApiListResponse<TestCountryItemListResp> response = xunFeiCommonApiService.getTestCountryItem(request, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            if (!CollectionUtils.isEmpty(response.getData())) {
                for (TestCountryItemListResp testCountryItemListResp : response.getData()) {
                    String[] hardware = testCountryItemListResp.getHardware().split(",");
                    StringBuilder sb = new StringBuilder();
                    for (String temp : hardware) {
                        //0 无默 认，1 手环，2 跳绳，3 秤， 4 手拍灯，5 仰卧起坐，6 肺活量
                        if (temp.equals("0")) {
                            sb.append("默认").append(" ");
                        } else if (temp.equals("1")) {
                            sb.append("臂带").append(" ");
                        } else if (temp.equals("2")) {
                            sb.append("跳绳").append(" ");
                        } else if (temp.equals("3")) {
                            sb.append("身高体重秤").append(" ");
                        } else if (temp.equals("4")) {
                            sb.append("短跑测试仪").append(" ");
                        } else if (temp.equals("5")) {
                            sb.append("仰卧起坐").append(" ");
                        } else if (temp.equals("6")) {
                            sb.append("肺活量").append(" ");
                        }else if (temp.equals("7")) {
                            sb.append("秒表").append(" ");
                        }else if (temp.equals("8")) {
                            sb.append("倒计时").append(" ");
                        }
                    }
                    testCountryItemListResp.setHardware(sb.toString());
                }
            }
            return MultiResponse.ofWithoutTotal(response.getData());
        }
        return MultiResponse.ofWithoutTotal(new ArrayList<>());
    }

    @ApiOperation(value = "总体情况-总分情况", notes = "总体情况-总分情况")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeReq")
    @PostMapping("/overall")
    public SingleResponse<PhysicalTestAllOverallResp> overall(@RequestBody QueryCourseTestGradeReq request) {
        QueryPhysicalTestAllOverallReq queryPhysicalTestAllOverallReq = new QueryPhysicalTestAllOverallReq();
        queryPhysicalTestAllOverallReq.setCampusId(request.getSchoolId());
        queryPhysicalTestAllOverallReq.setClassType(request.getClassType());
        queryPhysicalTestAllOverallReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestAllOverallReq.setClassId(request.getClassId());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiSingleResponse<PhysicalTestAllOverallResp> response = xunFeiTeachTestApiService.getPhysicalTestAllOverall(queryPhysicalTestAllOverallReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return SingleResponse.of(response.getData());
        }
        return SingleResponse.of(null);
    }

    @ApiOperation(value = "总体情况-具体项目-概述", notes = "成绩分析-具体项目-概述")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeReq")
    @PostMapping("/performance/analysis")
    public SingleResponse<PhysicalTestSingleOverallResp> performanceAnalysis(@RequestBody QueryCourseTestGradeReq request) {
        QueryPhysicalTestSingleOverallReq queryPhysicalTestSingleOverallReq = new QueryPhysicalTestSingleOverallReq();
        queryPhysicalTestSingleOverallReq.setCampusId(request.getSchoolId());
        queryPhysicalTestSingleOverallReq.setClassType(request.getClassType());
        queryPhysicalTestSingleOverallReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestSingleOverallReq.setSportItemId(request.getItemId());
        queryPhysicalTestSingleOverallReq.setClassId(request.getClassId());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiSingleResponse<PhysicalTestSingleOverallResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleOverall(queryPhysicalTestSingleOverallReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return SingleResponse.of(response.getData());
        }
        return SingleResponse.of(null);
    }


    @ApiOperation(value = "总体情况-附加分情况", notes = "总体情况-附加分情况")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @PostMapping("/physical/allAddition")
    public MultiResponse<PhysicalTestAllAdditionResp> physicalAllAddition(@RequestBody QueryCourseTestGradeListReq request) {
        QueryPhysicalTestAllAdditionReq queryPhysicalTestAllOverallReq = new QueryPhysicalTestAllAdditionReq();
        queryPhysicalTestAllOverallReq.setCampusId(request.getSchoolId());
        queryPhysicalTestAllOverallReq.setClassType(request.getClassType());
        queryPhysicalTestAllOverallReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestAllOverallReq.setClassId(request.getClassId());
        queryPhysicalTestAllOverallReq.setSportItemId(request.getItemId());
        queryPhysicalTestAllOverallReq.setPage(request.getPageNo());
        queryPhysicalTestAllOverallReq.setLimit(request.getPageSize());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestAllAdditionResp> response = xunFeiTeachTestApiService.getPhysicalTestAllAddition(queryPhysicalTestAllOverallReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.of(response.getData(), response.getTotal(), request);
        }
        return MultiResponse.of(new ArrayList<>(), 0, request);
    }

    @ApiOperation(value = "总体情况-导出附加分情况", notes = "总体情况-导出附加分情况")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @GetMapping("/physical/allAdditionExport")
    public void physicalAllAdditionExport(@RequestParam String schoolId, @RequestParam String classType, @RequestParam String cycleId,
                                          @RequestParam(required = false) String classId, @RequestParam(required = false) String itemId,
                                          @RequestParam(required = false) String grade) {


        QueryPhysicalTestAllAdditionReq queryPhysicalTestAllOverallReq = new QueryPhysicalTestAllAdditionReq();
        queryPhysicalTestAllOverallReq.setCampusId(schoolId);
        queryPhysicalTestAllOverallReq.setClassType(new Integer(classType));
        queryPhysicalTestAllOverallReq.setSportCycleId(cycleId);
        queryPhysicalTestAllOverallReq.setClassId(classId);
        queryPhysicalTestAllOverallReq.setSportItemId(itemId);
        queryPhysicalTestAllOverallReq.setPage(1);
        queryPhysicalTestAllOverallReq.setLimit(10000);
        if (null != grade && !grade.equals("null")) {
            Integer intGrader=new Integer(grade);
            if (intGrader < 7) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(intGrader));
            } else if (intGrader >= 7 && intGrader < 10) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(intGrader - 6));
            } else if (intGrader >= 10) {
                queryPhysicalTestAllOverallReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllOverallReq.setNj(String.valueOf(intGrader - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestAllAdditionResp> response = xunFeiTeachTestApiService.getPhysicalTestAllAddition(queryPhysicalTestAllOverallReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            List<PhysicalTestAllAdditionResp> list = response.getData();
            ExcelWriter writer = ExcelUtil.getWriter();
            writer.addHeaderAlias("studentName", "学生名称");
            writer.addHeaderAlias("xh", "学号");
            writer.addHeaderAlias("campusName", "校区");
            writer.addHeaderAlias("gradeInfo", "年级");
            writer.addHeaderAlias("className", "班级");
            writer.addHeaderAlias("itemName", "项目");
            writer.addHeaderAlias("mark", "成绩");
            writer.addHeaderAlias("itemUnit", "单位");
            writer.addHeaderAlias("score", "分数");
            writer.addHeaderAlias("addScore", "附加分");
            writer.addHeaderAlias("totalScore", "总分");
            writer.write(list, true);
            httpServletResponse.setContentType("application/vnd.ms-excel;charset=utf-8");
            httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + "allAdditionExport" + ".xls");
            ServletOutputStream out = null;
            try {
                out = httpServletResponse.getOutputStream();
                writer.flush(out, true);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                writer.close();
            }
            IoUtil.close(out);
        }
    }

    @ApiOperation(value = "总体情况-各项目成绩情况", notes = "总体情况-各项目成绩情况")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @PostMapping("/physical/allItem")
    public MultiResponse<PhysicalTestAllDetailResp> physicalAllItem(@RequestBody QueryCourseTestGradeListReq request) {
        QueryPhysicalTestAllDetailReq queryPhysicalTestAllDetailReq = new QueryPhysicalTestAllDetailReq();
        queryPhysicalTestAllDetailReq.setCampusId(request.getSchoolId());
        queryPhysicalTestAllDetailReq.setCampusName(request.getSchoolName());
        queryPhysicalTestAllDetailReq.setClassType(request.getClassType());
        queryPhysicalTestAllDetailReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestAllDetailReq.setSportItemId(request.getItemId());
        queryPhysicalTestAllDetailReq.setPage(request.getPageNo());
        queryPhysicalTestAllDetailReq.setLimit(request.getPageSize());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestAllDetailReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestAllDetailReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestAllDetailReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllDetailReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestAllDetailReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllDetailReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestAllDetailResp> response = xunFeiTeachTestApiService.getPhysicalTestAllDetail(queryPhysicalTestAllDetailReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.ofWithoutTotal(response.getData());
        }
        return MultiResponse.ofWithoutTotal(new ArrayList<>());
    }


    @ApiOperation(value = "成绩分析-全部情况", notes = "成绩分析-全部情况")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeReq")
    @PostMapping("/analyze/allItem")
    public MultiResponse<PhysicalTestAllAnalyzeResp> analyzeAllItem(@RequestBody QueryCourseTestGradeReq request) {
        QueryPhysicalTestAllAnalyzeReq queryPhysicalTestAllAnalyzeReq = new QueryPhysicalTestAllAnalyzeReq();
        queryPhysicalTestAllAnalyzeReq.setCampusId(request.getSchoolId());
        queryPhysicalTestAllAnalyzeReq.setClassType(request.getClassType());
        queryPhysicalTestAllAnalyzeReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestAllAnalyzeReq.setQueryType(request.getQueryType());
        queryPhysicalTestAllAnalyzeReq.setClassId(request.getClassId());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestAllAnalyzeReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestAllAnalyzeReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestAllAnalyzeReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllAnalyzeReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestAllAnalyzeReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllAnalyzeReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestAllAnalyzeResp> response = xunFeiTeachTestApiService.getPhysicalTestAllAnalyze(queryPhysicalTestAllAnalyzeReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.ofWithoutTotal(response.getData());
        }
        return MultiResponse.ofWithoutTotal(new ArrayList<>());
    }


    @ApiOperation(value = "成绩分析-单项-全部情况", notes = "成绩分析-单项-全部情况")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeReq")
    @PostMapping("/analyze/item")
    public SingleResponse<PhysicalTestSingleOverallResp> analyzeItem(@RequestBody QueryCourseTestGradeReq request) {
        QueryPhysicalTestSingleOverallReq queryPhysicalTestSingleOverallReq = new QueryPhysicalTestSingleOverallReq();
        queryPhysicalTestSingleOverallReq.setCampusId(request.getSchoolId());
        queryPhysicalTestSingleOverallReq.setClassType(request.getClassType());
        queryPhysicalTestSingleOverallReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestSingleOverallReq.setSportItemId(request.getItemId());
        queryPhysicalTestSingleOverallReq.setClassId(request.getClassId());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiSingleResponse<PhysicalTestSingleOverallResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleOverall(queryPhysicalTestSingleOverallReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return SingleResponse.of(response.getData());
        }
        return SingleResponse.buildFailure("接口无数据返回");
    }


    @ApiOperation(value = "成绩分析-单项-列表", notes = "成绩分析-单项-列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeReq")
    @PostMapping("/analyze/itemList")
    public MultiResponse<PhysicalTestSingleAnalyzeResp> analyzeItemList(@RequestBody QueryCourseTestGradeReq request) {
        QueryPhysicalTestSingleOverallReq queryPhysicalTestSingleOverallReq = new QueryPhysicalTestSingleOverallReq();
        queryPhysicalTestSingleOverallReq.setCampusId(request.getSchoolId());
        queryPhysicalTestSingleOverallReq.setClassType(request.getClassType());
        queryPhysicalTestSingleOverallReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestSingleOverallReq.setSportItemId(request.getItemId());
        queryPhysicalTestSingleOverallReq.setClassId(request.getClassId());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestSingleOverallReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleOverallReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestSingleAnalyzeResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleAnalyze(queryPhysicalTestSingleOverallReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.ofWithoutTotal(response.getData());
        }
        return MultiResponse.buildFailure("接口无数据返回");
    }


    @ApiOperation(value = "成绩详情-学生列表", notes = "成绩详情-学生列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @PostMapping("/single/detail")
    public MultiResponse<PhysicalTestSingleDetailResp> singleDetail(@RequestBody QueryCourseTestGradeListReq request) {
        QueryPhysicalTestSingleDetailReq queryPhysicalTestSingleDetailReq = new QueryPhysicalTestSingleDetailReq();
        queryPhysicalTestSingleDetailReq.setCampusId(request.getSchoolId());
        queryPhysicalTestSingleDetailReq.setClassType(request.getClassType());
        queryPhysicalTestSingleDetailReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestSingleDetailReq.setSportItemId(request.getItemId());
        queryPhysicalTestSingleDetailReq.setClassId(request.getClassId());
        queryPhysicalTestSingleDetailReq.setStudentName(request.getStudentName());
        queryPhysicalTestSingleDetailReq.setStart(request.getStart());
        queryPhysicalTestSingleDetailReq.setEnd(request.getEnd());
        queryPhysicalTestSingleDetailReq.setPage(request.getPageNo());
        queryPhysicalTestSingleDetailReq.setLimit(request.getPageSize());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestSingleDetailReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestSingleDetailReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestSingleDetailReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleDetailReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestSingleDetailReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleDetailReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestSingleDetailResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleDetail(queryPhysicalTestSingleDetailReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.of(response.getData(), response.getTotal(), request);
        }
        return MultiResponse.buildFailure("接口无数据返回");
    }

    @ApiOperation(value = "成绩详情-导出学生列表", notes = "成绩详情-导出学生列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @GetMapping("/single/detailExport")
    public void singleDetailExport(@RequestParam String schoolId, @RequestParam String classType, @RequestParam String cycleId,
                                   @RequestParam(required = false) String classId, @RequestParam(required = false) String itemId,
                                   @RequestParam(required = false) String grade, @RequestParam(required = false) String studentName,
                                   @RequestParam(required = false) String start, @RequestParam(required = false) String end) {
        QueryPhysicalTestSingleDetailReq queryPhysicalTestSingleDetailReq = new QueryPhysicalTestSingleDetailReq();
        queryPhysicalTestSingleDetailReq.setCampusId(schoolId);
        queryPhysicalTestSingleDetailReq.setClassType(new Integer(classType));
        queryPhysicalTestSingleDetailReq.setSportCycleId(cycleId);
        queryPhysicalTestSingleDetailReq.setSportItemId(itemId);
        queryPhysicalTestSingleDetailReq.setClassId(classId);
        queryPhysicalTestSingleDetailReq.setStudentName(studentName);
        if(null !=start){
            queryPhysicalTestSingleDetailReq.setStart(new Integer(start));
        }
        if(null !=end){
            queryPhysicalTestSingleDetailReq.setEnd(new Integer(end));
        }
        queryPhysicalTestSingleDetailReq.setPage(1);
        queryPhysicalTestSingleDetailReq.setLimit(10000);
        if (null != grade && !grade.equals("null")) {
            Integer intGrader=new Integer(grade);
            if (intGrader < 7) {
                queryPhysicalTestSingleDetailReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestSingleDetailReq.setNj(String.valueOf(intGrader));
            } else if (intGrader >= 7 && intGrader < 10) {
                queryPhysicalTestSingleDetailReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleDetailReq.setNj(String.valueOf(intGrader - 6));
            } else if (intGrader >= 10) {
                queryPhysicalTestSingleDetailReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestSingleDetailReq.setNj(String.valueOf(intGrader - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestSingleDetailResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleDetail(queryPhysicalTestSingleDetailReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS) && !CollectionUtils.isEmpty(response.getData())) {
            List<PhysicalTestSingleDetailResp> list = response.getData();
            ExcelWriter writer = ExcelUtil.getWriter();
            writer.addHeaderAlias("studentName", "学生名称");
            writer.addHeaderAlias("xh", "学号");
            writer.addHeaderAlias("campusName", "校区");
            writer.addHeaderAlias("gradeInfo", "年级");
            writer.addHeaderAlias("className", "班级");
            writer.addHeaderAlias("itemUnit", "单位");
            writer.addHeaderAlias("level", "级别");
            writer.addHeaderAlias("mark", "成绩");
            writer.addHeaderAlias("score", "分数");
            writer.addHeaderAlias("addScore", "附加分");
            writer.write(list, true);
            httpServletResponse.setContentType("application/vnd.ms-excel;charset=utf-8");
            httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + "detailExport" + ".xls");
            ServletOutputStream out = null;
            try {
                out = httpServletResponse.getOutputStream();
                writer.flush(out, true);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                writer.close();
            }
            IoUtil.close(out);
        }
    }

    @ApiOperation(value = "成绩详情-学生详情", notes = "成绩详情-学生详情")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeReq")
    @PostMapping("/item/score")
    public SingleResponse<PhysicalTestSingleUserDetailResp> itemScore(@RequestBody QueryCourseTestGradeReq request) {
        QueryPhysicalTestSingleUserDetailReq queryPhysicalTestSingleUserDetailReq = new QueryPhysicalTestSingleUserDetailReq();
        queryPhysicalTestSingleUserDetailReq.setStudentId(request.getStudentId());
        queryPhysicalTestSingleUserDetailReq.setClassType(request.getClassType());
        queryPhysicalTestSingleUserDetailReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestSingleUserDetailReq.setSportItemId(request.getItemId());
        queryPhysicalTestSingleUserDetailReq.setClassId(request.getClassId());
        ApiSingleResponse<PhysicalTestSingleUserDetailResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleUserDetail(queryPhysicalTestSingleUserDetailReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return SingleResponse.of(response.getData());
        }
        return SingleResponse.buildFailure("接口无数据返回");
    }



    @ApiOperation(value = "成绩管理-总分列表", notes = "成绩管理-总分列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @PostMapping("/physical/totalScore")
    public MultiResponse<PhysicalTestAllResultManagerResp> physicalTotalScoreList(@RequestBody QueryCourseTestGradeListReq request) {
        QueryPhysicalTestAllResultManagerReq queryPhysicalTestAllResultManagerReq = new QueryPhysicalTestAllResultManagerReq();
        queryPhysicalTestAllResultManagerReq.setCampusId(request.getSchoolId());
        queryPhysicalTestAllResultManagerReq.setClassType(request.getClassType());
        queryPhysicalTestAllResultManagerReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestAllResultManagerReq.setClassId(request.getClassId());
        queryPhysicalTestAllResultManagerReq.setStudentName(request.getStudentName());
        queryPhysicalTestAllResultManagerReq.setPage(request.getPageNo());
        queryPhysicalTestAllResultManagerReq.setLimit(request.getPageSize());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestAllResultManagerReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestAllResultManagerReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestAllResultManagerReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllResultManagerReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestAllResultManagerReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllResultManagerReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestAllResultManagerResp> response = xunFeiTeachTestApiService.getPhysicalTestAllResultManager(queryPhysicalTestAllResultManagerReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.of(response.getData(), response.getTotal(), request);
        }
        return MultiResponse.of(new ArrayList<>(), 0);
    }


    @ApiOperation(value = "成绩管理-总分列表-学生详情", notes = "成绩管理-总分列表-学生详情")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeDetailReq")
    @PostMapping("/physical/totalScoreDetail")
    public SingleResponse<PhysicalTestAllResultDetailResp> physicalTotalScoreDetail(@RequestBody QueryCourseTestGradeDetailReq request) {
        QueryPhysicalTestAllResultDetailReq queryPhysicalTestAllResultDetailReq = new QueryPhysicalTestAllResultDetailReq();
        queryPhysicalTestAllResultDetailReq.setStudentId(request.getStudentId());
        queryPhysicalTestAllResultDetailReq.setSportCycleId(request.getCycleId());
        ApiSingleResponse<PhysicalTestAllResultDetailResp> response = xunFeiTeachTestApiService.getPhysicalTestAllResultDetail(queryPhysicalTestAllResultDetailReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            List<PhysicalTestAllResultDetailResp.DetailListBean> addDetailList=new ArrayList<>();
            if(!CollectionUtils.isEmpty(response.getData().getDetailList())){
                for(PhysicalTestAllResultDetailResp.DetailListBean temp: response.getData().getDetailList()){
                        if(temp.getAddScore() != null){
                            addDetailList.add(temp);
                        }
                }
            }
            return SingleResponse.of(response.getData());
        }
        return SingleResponse.of(new PhysicalTestAllResultDetailResp());
    }

    @ApiOperation(value = "成绩管理-单项列表", notes = "成绩管理-单项列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @PostMapping("/physical/score")
    public MultiResponse<PhysicalTestAllResultManagerResp> physicalScoreList(@RequestBody QueryCourseTestGradeListReq request) {
        QueryPhysicalTestAllResultManagerReq queryPhysicalTestAllResultManagerReq = new QueryPhysicalTestAllResultManagerReq();
        queryPhysicalTestAllResultManagerReq.setCampusId(request.getSchoolId());
        queryPhysicalTestAllResultManagerReq.setClassType(request.getClassType());
        queryPhysicalTestAllResultManagerReq.setSportCycleId(request.getCycleId());
        queryPhysicalTestAllResultManagerReq.setSportItemId(request.getItemId());
        queryPhysicalTestAllResultManagerReq.setClassId(request.getClassId());
        queryPhysicalTestAllResultManagerReq.setStudentName(request.getStudentName());
        queryPhysicalTestAllResultManagerReq.setPage(request.getPageNo());
        queryPhysicalTestAllResultManagerReq.setLimit(request.getPageSize());
        if (null != request.getGrade()) {
            if (request.getGrade() < 7) {
                queryPhysicalTestAllResultManagerReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestAllResultManagerReq.setNj(String.valueOf(request.getGrade()));
            } else if (request.getGrade() >= 7 && request.getGrade() < 10) {
                queryPhysicalTestAllResultManagerReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllResultManagerReq.setNj(String.valueOf(request.getGrade() - 6));
            } else if (request.getGrade() >= 10) {
                queryPhysicalTestAllResultManagerReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestAllResultManagerReq.setNj(String.valueOf(request.getGrade() - 9));
            } else {
                throw new SysException("年级错误");
            }
        }
        ApiListResponse<PhysicalTestAllResultManagerResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleResultManager(queryPhysicalTestAllResultManagerReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return MultiResponse.of(response.getData(), response.getTotal(), request);
        }
        return MultiResponse.of(new ArrayList<>(), 0);
    }

    @ApiOperation(value = "成绩管理-导出班级列表", notes = "成绩管理-导出班级列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @GetMapping("/physical/classExport")
    public void physicalClassExport(@RequestParam String schoolId, @RequestParam Integer classType, @RequestParam String cycleIds,
                                        @RequestParam String classIds, @RequestParam String itemIds) {


        Map<String,String> itemIdMap=new LinkedHashMap<>();
        Map<String,String> itemNameMap=new LinkedHashMap<>();
        itemIdMap.put("98","BMI");
        itemIdMap.put("99","身高");
        itemIdMap.put("100","体重");
        itemNameMap.put("BMI","98");
        itemNameMap.put("身高","99");
        itemNameMap.put("体重","100");
        QueryPhysicalTestItemReq queryPhysicalTestItemReq = new QueryPhysicalTestItemReq();
        queryPhysicalTestItemReq.setType("0");
        ApiListResponse<PhysicalTestItemResp> response = xunFeiCommonApiService.getPhysicalTestItem(queryPhysicalTestItemReq,  getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            response.getData().forEach(o->{
                itemIdMap.put(o.getId(),o.getItemName());
                itemNameMap.put(o.getItemName(),o.getId());
            });
        }


        QueryPhysicalTestExportClassReq queryPhysicalTestAllResultManagerReq = new QueryPhysicalTestExportClassReq();
        queryPhysicalTestAllResultManagerReq.setCampusId(schoolId);
        queryPhysicalTestAllResultManagerReq.setClassType(classType);
        queryPhysicalTestAllResultManagerReq.setClassIdList(classIds);
        queryPhysicalTestAllResultManagerReq.setSportCycleIdList(cycleIds);
        queryPhysicalTestAllResultManagerReq.setSportItemIdList(itemIds);


        List<Map<String,String>> data=new ArrayList<>();
        ApiListResponse<PhysicalTestExportClassResp> response1 = xunFeiTeachTestApiService.getPhysicalTestExportClass(queryPhysicalTestAllResultManagerReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response1.getMsg() && response1.getMsg().equals(ApiResponse.SUCCESS) && !CollectionUtils.isEmpty(response1.getData())) {
            List<PhysicalTestExportClassResp> list = response1.getData();

            list.forEach(temp ->{
                Map<String,String> map=new LinkedHashMap<>();
                map.put("sportCycleName",temp.getSportCycleName());
                map.put("campusName",temp.getCampusName());
                map.put("gradeInfo",temp.getGradeInfo());
                map.put("className",temp.getClassName());
                map.put("studentName",temp.getStudentName());
                map.put("xh",temp.getXh());
                map.put("gender",temp.getGender());
                map.put("score",String.valueOf(temp.getScore()));
                map.put("addScore",String.valueOf(temp.getAddScore()));
                map.put("totalScore",String.valueOf(temp.getTotalScore()));
                map.put("level",temp.getLevel());
                List<PhysicalTestExportClassResp.ListBean> listBeans=temp.getList();
                if(CollectionUtil.isNotEmpty(listBeans)){
                    listBeans.forEach(listB->{
                        if(null != itemNameMap.get(listB.getSportItemName())){
                            map.put(itemNameMap.get(listB.getSportItemName()),String.valueOf(listB.getMark()));
                            map.put(itemNameMap.get(listB.getSportItemName())+"01",String.valueOf(listB.getScore()));
                            if(null != listB.getLevel()){
                                map.put(itemNameMap.get(listB.getSportItemName())+"02",String.valueOf(listB.getLevel()));
                            }
                        }
                    });
                }
                data.add(map);
            });


            ExcelWriter writer = ExcelUtil.getWriter();
            writer.addHeaderAlias("sportCycleName", "体测周期");
            writer.addHeaderAlias("campusName", "校区");
            writer.addHeaderAlias("gradeInfo", "年级");
            writer.addHeaderAlias("className", "班级");
            writer.addHeaderAlias("studentName", "学生名称");
            writer.addHeaderAlias("xh", "学号");
            writer.addHeaderAlias("gender", "性别");
            writer.addHeaderAlias("score", "分数");
            writer.addHeaderAlias("addScore", "附加分");
            writer.addHeaderAlias("totalScore", "总分");
            writer.addHeaderAlias("level", "级别");

            itemIdMap.forEach((a,b) ->{
                writer.addHeaderAlias(a, b);
                writer.addHeaderAlias(a+"01", b+"分数");
                writer.addHeaderAlias(a+"02", b+"级别");
            });

            writer.write(data, true);
            httpServletResponse.setContentType("application/vnd.ms-excel;charset=utf-8");
            httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + "classExport" + ".xls");
            ServletOutputStream out = null;
            try {
                out = httpServletResponse.getOutputStream();
                writer.flush(out, true);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                writer.close();
            }
            IoUtil.close(out);
        }
    }




    @ApiOperation(value = "成绩管理-导出个人列表", notes = "成绩管理-导出个人列表")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryCourseTestGradeListReq")
    @GetMapping("/physical/studentExport")
    public void physicalStundentExport(@RequestParam String xh, @RequestParam String cycleIds,@RequestParam String itemIds) {


        Map<String,String> itemIdMap=new LinkedHashMap<>();
        Map<String,String> itemNameMap=new LinkedHashMap<>();
        itemIdMap.put("98","BMI");
        itemIdMap.put("99","身高");
        itemIdMap.put("100","体重");
        itemNameMap.put("BMI","98");
        itemNameMap.put("身高","99");
        itemNameMap.put("体重","100");
        QueryPhysicalTestItemReq queryPhysicalTestItemReq = new QueryPhysicalTestItemReq();
        queryPhysicalTestItemReq.setType("0");
        ApiListResponse<PhysicalTestItemResp> response = xunFeiCommonApiService.getPhysicalTestItem(queryPhysicalTestItemReq,  getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            response.getData().forEach(o->{
                itemIdMap.put(o.getId(),o.getItemName());
                itemNameMap.put(o.getItemName(),o.getId());
            });
        }

        QueryPhysicalTestExportStudentReq testExportStudentReq = new QueryPhysicalTestExportStudentReq();
        testExportStudentReq.setXh(xh);
        testExportStudentReq.setSportCycleIdList(cycleIds);
        testExportStudentReq.setSportItemIdList(itemIds);


        List<Map<String,String>> data=new ArrayList<>();
        ApiListResponse<PhysicalTestExportStudentResp> response1 = xunFeiTeachTestApiService.getPhysicalTestExportStudent(testExportStudentReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response1.getMsg() && response1.getMsg().equals(ApiResponse.SUCCESS) && !CollectionUtils.isEmpty(response1.getData())) {
            List<PhysicalTestExportStudentResp> list = response1.getData();

            list.forEach(temp ->{
                Map<String,String> map=new LinkedHashMap<>();
                map.put("sportCycleName",temp.getSportCycleId());
                map.put("campusName",temp.getCampusName());
                map.put("gradeInfo",temp.getGradeInfo());
                map.put("className",temp.getClassName());
                map.put("studentName",temp.getStudentName());
                map.put("xh",temp.getXh());
                map.put("gender",temp.getGender());
                map.put("score",String.valueOf(temp.getScore()));
                map.put("addScore",String.valueOf(temp.getAddScore()));
                map.put("totalScore",String.valueOf(temp.getTotalScore()));
                map.put("level",temp.getLevel());
                List<PhysicalTestExportStudentResp.ListBean> listBeans=temp.getList();
                if(CollectionUtil.isNotEmpty(listBeans)){
                    listBeans.forEach(listB->{
                        if(null != itemNameMap.get(listB.getSportItemName())){
                            map.put(itemNameMap.get(listB.getSportItemName()),String.valueOf(listB.getMark()));
                            map.put(itemNameMap.get(listB.getSportItemName())+"01",String.valueOf(listB.getScore()));
                            if(null != listB.getLevel()){
                                map.put(itemNameMap.get(listB.getSportItemName())+"02",String.valueOf(listB.getLevel()));
                            }
                        }
                    });
                }
                data.add(map);
            });


            ExcelWriter writer = ExcelUtil.getWriter();
            writer.addHeaderAlias("sportCycleName", "体测周期");
            writer.addHeaderAlias("campusName", "校区");
            writer.addHeaderAlias("gradeInfo", "年级");
            writer.addHeaderAlias("className", "班级");
            writer.addHeaderAlias("studentName", "学生名称");
            writer.addHeaderAlias("xh", "学号");
            writer.addHeaderAlias("gender", "性别");
            writer.addHeaderAlias("score", "分数");
            writer.addHeaderAlias("addScore", "附加分");
            writer.addHeaderAlias("totalScore", "总分");
            writer.addHeaderAlias("level", "级别");

            itemIdMap.forEach((a,b) ->{
                writer.addHeaderAlias(a, b);
                writer.addHeaderAlias(a+"01", b+"分数");
                writer.addHeaderAlias(a+"02", b+"级别");
            });

            writer.write(data, true);
            httpServletResponse.setContentType("application/vnd.ms-excel;charset=utf-8");
            httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + "studentExport" + ".xls");
            ServletOutputStream out = null;
            try {
                out = httpServletResponse.getOutputStream();
                writer.flush(out, true);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                writer.close();
            }
            IoUtil.close(out);
        }
    }



    @ApiOperation(value = "成绩管理-详情", notes = "成绩管理-详情")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryStudentTestScoreInfoReq")
    @PostMapping("/score/info")
    public SingleResponse<PhysicalTestSingleResultHistoryResp> scoreInfo(@RequestBody QueryStudentTestScoreInfoReq request) {
        QueryPhysicalTestSingleResultHistoryReq queryPhysicalTestSingleResultHistoryReq = new QueryPhysicalTestSingleResultHistoryReq();
        queryPhysicalTestSingleResultHistoryReq.setStudentId(request.getStudentId());
        queryPhysicalTestSingleResultHistoryReq.setSportCycleId(request.getSportCycleId());
        queryPhysicalTestSingleResultHistoryReq.setSportItemId(request.getSportItemId());
        ApiSingleResponse<PhysicalTestSingleResultHistoryResp> response = xunFeiTeachTestApiService.getPhysicalTestSingleResultHistory(queryPhysicalTestSingleResultHistoryReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return SingleResponse.of(response.getData());
        }
        return SingleResponse.buildFailure("接口无数据返回");
    }

    @ApiOperation(value = "成绩管理-修改", notes = "成绩管理-修改")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "UpdateStudentTestScoreReq")
    @PostMapping("/score/update")
    public Response updateScore(@RequestBody UpdateStudentTestScoreReq request) {
        UpdatePhysicalTestSingleResultHistoryReq updatePhysicalTestSingleResultHistoryReq = new UpdatePhysicalTestSingleResultHistoryReq();
        updatePhysicalTestSingleResultHistoryReq.setStudentId(request.getStudentId());
        updatePhysicalTestSingleResultHistoryReq.setSportCycleId(request.getSportCycleId());
        updatePhysicalTestSingleResultHistoryReq.setSportItemId(request.getSportItemId());
        updatePhysicalTestSingleResultHistoryReq.setMark(request.getMark());
        ApiSingleResponse<Boolean> response = xunFeiTeachTestApiService.updatePhysicalTestSingleResultHistory(updatePhysicalTestSingleResultHistoryReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return Response.buildSuccess();
        }
        return Response.buildFailure("接口无数据返回");
    }


    @ApiOperation(value = "成绩管理-删除", notes = "成绩管理-删除")
    @ApiImplicitParam(name = "request", value = "请求对象", required = true, dataType = "QueryStudentTestScoreInfoReq")
    @PostMapping("/score/del")
    public Response delScore(@RequestBody QueryStudentTestScoreInfoReq request) {
        QueryPhysicalTestSingleResultHistoryReq queryPhysicalTestSingleResultHistoryReq = new QueryPhysicalTestSingleResultHistoryReq();
        queryPhysicalTestSingleResultHistoryReq.setStudentId(request.getStudentId());
        queryPhysicalTestSingleResultHistoryReq.setSportCycleId(request.getSportCycleId());
        queryPhysicalTestSingleResultHistoryReq.setSportItemId(request.getSportItemId());
        ApiSingleResponse<Boolean> response = xunFeiTeachTestApiService.deletePhysicalTestSingleResultHistory(queryPhysicalTestSingleResultHistoryReq, getPartyId().toString(), null, getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            return Response.buildSuccess();
        }
        return Response.buildFailure("接口无数据返回");
    }




    @ApiOperation(value = "成绩上报-下载", notes = "成绩上报-下载")
    @GetMapping("/physical/testDown")
    public void physicalTestDown(@RequestParam String schoolId,@RequestParam String cycleId,
                                        @RequestParam(required = false) String classId,
                                        @RequestParam(required = false) Integer grade) {

        Map<String,String> itemIdMap=new LinkedHashMap<>();
        Map<String,String> itemNameMap=new LinkedHashMap<>();
        itemIdMap.put("98","BMI");
        itemIdMap.put("99","身高");
        itemIdMap.put("100","体重");
        itemNameMap.put("BMI","98");
        itemNameMap.put("身高","99");
        itemNameMap.put("体重","100");
        QueryPhysicalTestItemReq queryPhysicalTestItemReq = new QueryPhysicalTestItemReq();
        queryPhysicalTestItemReq.setType("0");
        ApiListResponse<PhysicalTestItemResp> response = xunFeiCommonApiService.getPhysicalTestItem(queryPhysicalTestItemReq,  getPartyId().toString(), null,getUserId().toString());
        if (null != response.getMsg() && response.getMsg().equals(ApiResponse.SUCCESS)) {
            response.getData().forEach(o->{
                itemIdMap.put(o.getId(),o.getItemName());
                itemNameMap.put(o.getItemName(),o.getId());
            });
        }


        QueryPhysicalTestDownReq queryPhysicalTestDownReq = new QueryPhysicalTestDownReq();
        queryPhysicalTestDownReq.setCampusId(schoolId);
        queryPhysicalTestDownReq.setSportCycleId(cycleId);
        queryPhysicalTestDownReq.setClassId(classId);
        if (null != grade) {
            if (grade < 7) {
                queryPhysicalTestDownReq.setSectionId(SectionEnum.PRIMARY_SCHOOL.getAlias());
                queryPhysicalTestDownReq.setNj(String.valueOf(grade));
            } else if (grade >= 7 && grade < 10) {
                queryPhysicalTestDownReq.setSectionId(SectionEnum.JUNIOR_HIGH_SCHOOL.getAlias());
                queryPhysicalTestDownReq.setNj(String.valueOf(grade - 6));
            } else if (grade >= 10) {
                queryPhysicalTestDownReq.setSectionId(SectionEnum.HIGH_SCHOOL.getAlias());
                queryPhysicalTestDownReq.setNj(String.valueOf(grade - 9));
            } else {
                throw new SysException("年级错误");
            }
        }

        List<Map<String,String>> data=new ArrayList<>();
        ApiListResponse<PhysicalTestDownloadResp> downloadRespApiListResponse = xunFeiTeachTestApiService.getPhysicalTestDownload(queryPhysicalTestDownReq, getPartyId().toString(), null,getUserId().toString());
        if (null != downloadRespApiListResponse.getMsg() && downloadRespApiListResponse.getMsg().equals(ApiResponse.SUCCESS) && !CollectionUtils.isEmpty(downloadRespApiListResponse.getData())) {
            List<PhysicalTestDownloadResp> list = downloadRespApiListResponse.getData();
            list.forEach(temp ->{
                Map<String,String> map=new LinkedHashMap<>();
                map.put("gradeInfo",temp.getGradeInfo());
                map.put("className",temp.getClassName());
                map.put("studentName",temp.getStudentName());
                map.put("xh",temp.getXh());
                map.put("gender",temp.getGender());
                map.put("birthDate",temp.getBirthDate());
                List<PhysicalTestDownloadResp.ListBean> listBeans=temp.getList();
                listBeans.forEach(listB->{
                    if(null != itemNameMap.get(listB.getSportItemName())){
                        map.put(itemNameMap.get(listB.getSportItemName()),String.valueOf(listB.getMark()));
                    }
                });
                data.add(map);
            });

            ExcelWriter writer = ExcelUtil.getWriter();
            writer.addHeaderAlias("gradeInfo", "年级");
            writer.addHeaderAlias("className", "班级");
            writer.addHeaderAlias("studentName", "学生名称");
            writer.addHeaderAlias("xh", "学号");
            writer.addHeaderAlias("gender", "性别");
            writer.addHeaderAlias("birthDate", "出生日期");
            itemIdMap.forEach((a,b) ->{
                writer.addHeaderAlias(a, b);
            });
            writer.write(data, true);
            httpServletResponse.setContentType("application/vnd.ms-excel;charset=utf-8");
            httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + "testDownLoad" + ".xls");
            ServletOutputStream out = null;
            try {
                out = httpServletResponse.getOutputStream();
                writer.flush(out, true);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                writer.close();
            }
            IoUtil.close(out);
        }
    }

}
